/*
 * Test.cpp
 *
 *  Created on: 2010-5-30
 *      Author: guobc
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstring>

using namespace std;

namespace HA {

class Tools {

private:
	inline static char toUpper(char ch) {
		return toupper(ch);
	}

	inline static char toLower(char ch) {
		return tolower(ch);
	}

public:
	inline static string toUpperCase(string& str) {
		transform(str.begin(), str.end(), str.begin(), toUpper);
		return str;
	}

	inline static string toLowerCase(string& str) {
		transform(str.begin(), str.end(), str.begin(), toLower);
		return str;
	}

	inline static int lastIndexOf(const char* source, const char* target){
		int sourceCount = strlen(source);
		int targetCount = strlen(target);
		if(targetCount > sourceCount)return - 1;
		char lastChar = target[targetCount - 1];
		bool allEqual = true;
		for(int i = sourceCount - 1; i >= 0; i--){
			char srcChar = source[i];
			if(srcChar == lastChar){
				int k = i - 1;
				for(int j = targetCount - 2; j >= 0 && k >=0; j--, k--){
					if(target[j] != source[k]){
						allEqual = false;
						break;
					}
				}
				if(allEqual){
					return k + 1;
				}
			}
		}
		return -1;
	}

};
}

